package com.adaptiveAgingAdmin.controller;

import com.adaptiveAgingAdmin.code.Code;
import com.adaptiveAgingAdmin.code.Result;
import com.adaptiveAgingAdmin.service.PublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping( "/public")
public class PublicController {

    @Autowired
    private PublicService publicService;

    @PostMapping("/login")
    Result login(@RequestParam String username, @RequestParam String password){
        Map data=publicService.checkLogin(username,password);
        return data!=null?Result.OK(data,"登录成功!"):Result.ERR(null,"登录失败!");
    }

    @PostMapping("/refresh")
    Result refresh(@RequestParam String refreshToken){
        Map data = publicService.refreshToken(refreshToken);
        return data!=null?Result.OK(data,null):Result.ERR(null,"获取失败!");
    }
    @PostMapping("/heartBeat")
    Result heartBeat(@RequestParam Long id){
        Map data = publicService.heartBeat(id);
        return data!=null?new Result(Code.NOT_LOGIN,data,"您已被强制下线!"):Result.OK(null,null);
    }
}
